﻿using UnityEngine;
using UnityEngine.UI;
using Jinndev.UI;

namespace Jinndev {

    /// <summary>
    /// 地图上的瓦片物体
    /// </summary>
    public class MapTileObjUI : BaseUIBehaviour {

        public static readonly string PATH = "Prefab/UI/MapEditor/Map/MapTileObjUI";

        public RawImage image;

        public MapObjData data;

        public bool hovered;
        public bool selected;
        public int layer;


        public void Refresh(MapObjData data, int layer) {
            this.data = data;
            this.layer = layer;
            MapUtil.SetTileTextureAndScale(image, data);
        }

        public void ToggleHover(bool hovered) {
            this.hovered = hovered;
            RefreshColor();
        }

        public void ToggleSelected(bool selected) {
            this.selected = selected;
            RefreshColor();
        }

        public void RefreshColor() {
            if (selected) {
                image.color = new Color(0, 1, 1);
            }
            else if (hovered) {
                image.color = new Color(0, 1, 0);
            }
            else {
                image.color = Color.white;
            }
        }

    }


}
